package com.example.meterialproject.activitys.transition.demo7

import android.os.Bundle
import androidx.core.os.bundleOf
import androidx.navigation.Navigation
import com.example.meterialproject.R
import com.example.meterialproject.base.BaseActivity
import com.example.meterialproject.databinding.ActivityTransitionDemo7Binding
import com.example.meterialproject.exts.click
import com.example.meterialproject.exts.getSelectIndex
import com.example.meterialproject.exts.toast

/**
 *
 * @ClassName: TransitionDemo7Activity
 * @Author: android 超级兵
 * @CreateDate: 4/28/22$ 2:11 PM$
 * TODO
 */
class TransitionDemo7Activity : BaseActivity<ActivityTransitionDemo7Binding>() {

    // 账号
    private var mAccount: String? = null

    // 验证码
    private var mVCode: String? = null

    // 密码
    private var mPwd: String? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // back
        binding.btnBack.click {
            binding.btnNext.text = "下一页"
            isNext(true)
            Navigation.findNavController(binding.fragmentView).popBackStack()
        }

        // next
        binding.btnNext.click {
            isNext(false)
            if (binding.btnNext.text != "完成") {
                Navigation.findNavController(binding.fragmentView).navigate(
                    R.id.SMSFragment,
                    bundleOf(
                        SMSFragment.TYPE to binding.chipGroup.getSelectIndex(),
                        SMSFragment.ACCOUNT to mAccount,
                        SMSFragment.PWD to mPwd,
                    ),
                )
            } else {
                "账号:$mAccount\n密码:${mPwd}\nvCode:$mVCode" toast this
            }

            binding.btnNext.text = "完成"
        }
    }

    private fun isNext(isNext: Boolean) {
        binding.btnNext.isEnabled = isNext
        binding.btnBack.isEnabled = !isNext
    }

    /*
     * 作者:android 超级兵
     * 创建时间: 4/29/22 9:51 AM
     * TODO 接收 AccountFragment
     */
    fun takeOverAccount(isNext: Boolean, account: String?, pwd: String?) {
        if (isNext) {
            isNext(true)
        }

        mAccount = account
        mPwd = pwd
    }

    /*
     * 作者:android 超级兵
     * 创建时间: 4/29/22 9:49 AM
     * TODO 接手 SMSFragment
     * @param isOver : 是否完成
     * @param account: 账号
     * @param pwd: 密码
     * @param vCode: 验证码
     */
    fun takeOverSMS(isOver: Boolean, account: String, pwd: String, vCode: String) {
        if (isOver) {
            mAccount = account
            mPwd = pwd
            mVCode = vCode
        }
        isNext(isOver)
    }
}